Add MqttManager for broker connection lifecycle (CATROID-1671)#5222
Open
Paras-ydv wants to merge 9 commits into
Open
Add MqttManager for broker connection lifecycle (CATROID-1671)#5222Paras-ydv wants to merge 9 commits into
Paras-ydv wants to merge 9 commits into
Conversation
Add the Eclipse Paho MQTT Java library dependency to the Catroid module's build configuration. This lays the groundwork for the connection manager and the new MQTT bricks. - Declare org.eclipse.paho.client.mqttv3:1.2.5 via Maven Central (Eclipse Paho repo not required) - Declare org.eclipse.paho.android.service:1.1.1 via Maven Central - Add FEATURE_MQTT_ENABLED build config flag in build.gradle - Register MqttService in AndroidManifest.xml - Add MqttDependencySanityTest to verify Paho classes are accessible on the test classpath INTERNET and ACCESS_NETWORK_STATE permissions were already present in the manifest — no changes required.
…d default host, disable MQTT settings if feature is not enabled
- Add MqttClientInterface to decouple MqttManager from Paho - Add PahoMqttClient as thin production wrapper around MqttClient - Add MqttConnectionConfig to group broker connection parameters - Add MqttManager with connect/disconnect, connection state tracking, URI and options building, and graceful failure handling with logging - Close client on connect failure to prevent resource leaks - Fix getMqttHost fallback default to 192.168.0.1 (regression in cherry-picked dependency commit) - Add unit tests covering full connection lifecycle and state Depends on: mqtt-settings-entry-task-tdd (CATROID-1670, CATROID-1672) This PR should only be merged after that PR is merged and rebased.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
This PR implements the centralized MQTT Manager for Catroid, responsible for the full connection lifecycle of an MQTT broker client:
This ticket is scoped to connection management only. Message publishing, subscriptions, and MQTT bricks are deferred to separate tickets.
CATROID-1671 — MqttManager for Broker Connection Lifecycle
Changes Implemented
org.catrobat.catroid.devices.mqttMqttClientInterfaceAbstracts the Paho client behind an interface, decoupling
MqttManagerfrom the third-party library and enabling pure JVM unit tests without an Android runtime or real network.PahoMqttClientThin adapter wrapping
org.eclipse.paho.client.mqttv3.MqttClientbehindMqttClientInterface. Used in production.MqttConnectionConfigData class grouping all six broker parameters (host, port, clientId, username, password, TLS flag). Includes a
fromContext()factory that reads values fromSettingsFragment. Keepsconnect()to a single overload with one parameter.MqttManagerCore manager class:
by lazy— follows the same pattern asRaspberryPiServiceconnect(config)— establishes broker connection, idempotent if already connected, validates host, auto-generates client ID if blankconnectFromContext(context)— convenience entry point reading config fromSettingsFragmentdisconnect()— graceful disconnect and resource cleanup, idempotent if not connectedisConnected— queryable connection state backed by the clientbuildServerUri()— producestcp://orssl://URI based on TLS flagbuildConnectOptions()— sets clean session, timeout, and optional credentialsclose()on the client to release any allocated resources, nulls the reference — app never crashesTesting
Added
MqttManagerTestwith 26 unit tests usingFakeMqttClient(hand-written test double — no Mockito, no emulator, pure JVM):isConnectedis false before any callconnect()success path: returns true, calls client, sets callbackconnect()failure path: returns false without crashing whenMqttExceptionthrown, callsclose()for resource cleanupconnect()guard paths: already connected returns true without reconnecting; blank host returns false without touching client; empty client ID auto-generates onetcp://vsssl://scheme selection, full URI formatisCleanSessionalways true, credentials set only when non-blankdisconnect(): callsdisconnect()andclose()on client; skips both when not connected; safe to call twiceFollowed TDD workflow:
26 unit tests added.
Static Analysis
Your Checklist